//
//  WCG_O_SingleTableViewCell.m
//  Project_B
//
//  Created by 黑黑 on 15/11/25.
//  Copyright © 2015年 Atom_Wang. All rights reserved.
//

#import "WCG_O_SingleTableViewCell.h"
#import "WCG_O_SingleCollectionViewCell.h"

@interface WCG_O_SingleTableViewCell () <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>

@end

@implementation WCG_O_SingleTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
    }
    return self;
}

- (void)createCollectionView
{
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = self.frame.size;
    self.flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.flowLayout.minimumInteritemSpacing = 0;
    self.flowLayout.minimumLineSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 10, self.contentView.frame.size.width, self.contentView.frame.size.height -20) collectionViewLayout:self.flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource =self;
    self.collectionView.emptyDataSetSource = self;
    self.collectionView.emptyDataSetDelegate = self;
    self.collectionView.scrollEnabled = NO;
    self.collectionView.scrollsToTop = NO;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.pagingEnabled = YES;
    self.collectionView.bounces = NO;
    [self.contentView addSubview:self.collectionView];
    [self.collectionView registerClass:[WCG_O_SingleCollectionViewCell class] forCellWithReuseIdentifier:@"collection"];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.collectionView == scrollView ) {
        CGFloat index = self.collectionView.contentOffset.x / self.contentView.frame.size.width;
        [self.delegate changButtonViewByIndex:index];
    }
}

- (void)changeCollectionByIndex:(NSInteger)index
{
    [self.collectionView setContentOffset:CGPointMake(self.contentView.frame.size.width * index, 0) animated:YES];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    /**
     *  collectionVie的cell是一个tableView 在这里我们定义了四个tableView而4个tableView对应四个不同样式的tableViewcell
     */
    WCG_O_SingleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];    
    cell.index = indexPath.row;
    cell.itemArr = self.itemArr;
    cell.cpArr = self.cpArr;
    cell.specialModel = self.specialModel;
    [cell.tableView reloadData];
    
    return cell;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width, self.contentView.frame.size.height);
    
    self.collectionView.frame = CGRectMake(0,0, self.contentView.frame.size.width, self.contentView.frame.size.height);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 当数据为空时显示的图片
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return [UIImage imageNamed:@"icon-search-article"];
}

#pragma mark - 当数据为空时显示的字符
-(NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    NSString *text = @"还没有收藏文章哦~";
    NSDictionary *str = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]};
    return [[NSAttributedString alloc] initWithString:text attributes:str];
}


@end
